package com.jcompressor.model.resources;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang.ObjectUtils;
import org.apache.commons.lang.builder.ToStringBuilder;

import com.jcompressor.model.config.Resource;
import com.jcompressor.type.ResourceType;

public class Template implements Serializable {
	
	private static final long serialVersionUID = -4863905813524931927L;
	
	private String id;
	private List<Resource> resources;
	
	public Template() {
		this.resources = new ArrayList<Resource>();
	}
	
	public String getId() {
		return this.id;
	}
	
	public List<Resource> getResources() {
		return this.resources;
	}
	
	public List<Resource> getResources(final ResourceType type) {
		final List<Resource> resources = new ArrayList<Resource>();
		for (final Resource resource : this.resources) {
			if (ObjectUtils.equals(resource.getType(), type)) {
				resources.add(resource);
			}
		}
		
		return resources;
	}
	
	public void setId(final String id) {
		this.id = id;
	}
	
	public void setResources(final List<Resource> resources) {
		this.resources = resources;
	}
	
	public void addResource(final Resource resource) {
		this.resources.add(resource);
	}
	
	/**
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return new ToStringBuilder(this)
			.append("ID", this.getId())
			.toString();
	}
	
}